﻿

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace MainMenu
{
    /// <summary>
    /// 主菜单面板
    /// </summary>
    public class MenuPanel : MonoBehaviour
    {
        #region 主菜单面板字段
        /// <summary>
        /// 开始游戏按钮
        /// </summary>
        public Button playbutton;

        /// <summary>
        /// 排行榜按钮
        /// </summary>
        public Button ratebutton;

        /// <summary>
        /// 声音按钮
        /// </summary>
        public Button soundbutton;

        /// <summary>
        /// 主题按钮
        /// </summary>
        public Button themebutton;

        /// <summary>
        /// 收藏按钮
        /// </summary>
        public Button descbutton;

        /// <summary>
        /// 背景图
        /// </summary>
        public RawImage bg;

        /// <summary>
        /// 背景列表
        /// </summary>
        public List<Texture> bglist;
        #endregion

        private void Awake()
        {
            string bgname = PlayerPrefs.GetString("bg");
            if (bgname != null )
            bg.texture = Resources.Load<Texture>("bg/" + bgname);
            if (playbutton != null)
            {
                playbutton.onClick.AddListener(OnplayButtonClick);
            }
            if(ratebutton!=null)
            {
                ratebutton.onClick.AddListener(OnrateButtonClick);
            }
            if(soundbutton!=null)
            {
                soundbutton.onClick.AddListener (OnsoundButtonClick);
            }
            if(themebutton!=null)
            {
                themebutton.onClick.AddListener(OnthemeButtonClick);
            }
            if(descbutton!=null)
            {
                descbutton.onClick.AddListener(OndescButtonClick);
            }
        }

        #region 菜单面板函数
        /// <summary>
        /// 游戏开始点击事件
        /// </summary>
        public void OnplayButtonClick()
        {
            UIManager.Instance.GameModePanel.Show();
        }

        /// <summary>
        /// 排行榜点击事件
        /// </summary>
        public void OnrateButtonClick() 
        {
            
        }

        /// <summary>
        /// 声音点击事件
        /// </summary>
        public void OnsoundButtonClick()
        {
            UIManager.Instance.MusicPanel.Show();
        }

        /// <summary>
        /// 主题点击事件
        /// </summary>
        public void OnthemeButtonClick()
        {
           
            UIManager.Instance.ThemePanel.Show();
            UIManager.Instance.ThemePanel.RefreshThemeAllItem();
        }

        /// <summary>
        /// 设置选中的背景
        /// </summary>
        /// <param name="selectbg"></param>
        public void SetBgTexture(Texture selectbg)
        {
            bg.texture= selectbg;
        }

        /// <summary>
        /// 收藏点击事件
        /// </summary>
        public void OndescButtonClick()
        {

        }
        #endregion

    }
}